package zhuanyeshixi2.basic.vo;

/**
 * 基础消息响应对象
 */
public class BasicMsg {
    private String operateResult;
    private String errorMsg;
    private Object data;

    // 构造方法
    public BasicMsg() {
    }

    public BasicMsg(String operateResult, String errorMsg, Object data) {
        this.operateResult = operateResult;
        this.errorMsg = errorMsg;
        this.data = data;
    }

    // 成功静态方法
    public static BasicMsg success() {
        return new BasicMsg("SUCCESS", null, null);
    }

    public static BasicMsg success(Object data) {
        return new BasicMsg("SUCCESS", null, data);
    }

    public static BasicMsg success(String message, Object data) {
        return new BasicMsg("SUCCESS", message, data);
    }

    // 失败静态方法
    public static BasicMsg fail(String errorMsg) {
        return new BasicMsg("FAIL", errorMsg, null);
    }

    public static BasicMsg fail(Enum<?> errorCode, String errorMsg) {
        return new BasicMsg("FAIL", errorCode.name() + ": " + errorMsg, null);
    }

    // Getter 和 Setter 方法
    public String getOperateResult() {
        return operateResult;
    }

    public void setOperateResult(String operateResult) {
        this.operateResult = operateResult;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    // 便捷方法
    public boolean isSuccess() {
        return "SUCCESS".equals(operateResult);
    }

    public boolean isFail() {
        return "FAIL".equals(operateResult);
    }

    @Override
    public String toString() {
        return "BasicMsg{" +
                "operateResult='" + operateResult + '\'' +
                ", errorMsg='" + errorMsg + '\'' +
                ", data=" + data +
                '}';
    }
}